#include "..\headers\ListOf.h"

#define InitSize 100
typedef int ElemType;

typedef struct Stack {
  ElemType *top;
  ElemType *base;
  int StackSize;
} SqStack;

int InitStack(SqStack &stack) {
  stack.base = (ElemType *)malloc(sizeof(Stack) * InitSize);
  if (!stack.base) {
    printf("ERROR:FAIL IN INITSTACK");
    return ERROR;
  }
  stack.top = stack.base;
  stack.StackSize = InitSize;
  return OK;
}

// push the element to stack top
int Push(SqStack &S, ElemType e) {
  if (S.top - S.base == S.StackSize) {
    printf("ERROR:IS FULLSTACK");
    return ERROR;
  }
  *S.top++ = e;
  return OK;
}

// pop the top element
int Pop(SqStack &S, ElemType &e) {
  if (S.top == S.base) {
    printf("ERROR:STACK IS EMPTY");
    return ERROR;
  }
  e = *S.top--;
  return OK;
}

// get top element in stack but do not change stack
int GetTop(SqStack S, ElemType &e) {
  if (S.top == S.base) {
    printf("ERROR:STACK IS EMPTY");
    return ERROR;
  }
  e = *S.top;
  return OK;
}

// if stack is empty return true else return false
bool EmptyStack(SqStack S) { return S.top == S.base; }

int main() {
  SqStack S;
  InitStack(S);
}
